package com.biyao.controller.base;


import com.baomidou.mybatisplus.plugins.Page;
import com.biyao.schedulingcommon.response.BaseMsg;
import com.biyao.schedulingcommon.response.FailureMsg;
import com.biyao.schedulingcommon.response.SuccessMsg;
import com.biyao.schedulingentity.base.TBearingBoxEntity;
import com.biyao.service.model.base.imp.TBearingBoxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 
 *
 * @author code generator
 * @date 2019-09-16 09:44:07
 */
@Api(tags = {"轴承箱信息"})
@RestController
@RequestMapping("api/v1/tbearingbox")
public class TBearingBoxController {

    @Autowired
    private TBearingBoxService tBearingBoxService;

    /**
    * 待完善
    * @param pageNum 待完善
    * @param pageSize 待完善
    * @return  待完善
    */
    @ApiOperation(value = "列表")
    @GetMapping
    public BaseMsg list(@RequestParam(defaultValue = "1") Integer pageNum,
                        @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        Page page = tBearingBoxService.list(pageNum, pageSize);

        return new SuccessMsg(page);
    }




    @ApiOperation(value = "详情")
    @GetMapping("/info/{id}")
    public BaseMsg info(@PathVariable("id") Integer id) {
            TBearingBoxEntity tBearingBox = tBearingBoxService.selectById(id);
        return new SuccessMsg(tBearingBox);
    }


    @ApiOperation(value = "保存")
    @PostMapping
    public BaseMsg save(@RequestBody TBearingBoxEntity tBearingBox) {
        if(tBearingBoxService.selectCodeIsRepeat(tBearingBox.getCode())){
            return new FailureMsg(500,"代号重复");
        }
        tBearingBoxService.insert(tBearingBox);
        return new SuccessMsg();
    }

    @ApiOperation(value = "更新")
    @PutMapping
    public BaseMsg update(@RequestBody TBearingBoxEntity tBearingBox) {
        if(tBearingBoxService.selectUpdateCodeIsRepeat(tBearingBox.getCode(),tBearingBox.getId())){
            return new FailureMsg(500,"代号重复");
        }
        tBearingBoxService.updateAllColumnById(tBearingBox);

        return new SuccessMsg();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("delete/{id}")
    public BaseMsg delete(@PathVariable("id") Integer id) {
        tBearingBoxService.deleteById(id);
        return new SuccessMsg();
    }

    @ApiOperation(value = "轴承座当前信息查询")
    @GetMapping("/nowInfo/{id}")
    public BaseMsg nowInfo(@PathVariable("id") Integer id){
       return new SuccessMsg(tBearingBoxService.getRollerByBox(id));
    }




}
